// pages/special/special.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this; console.log(options);
    const app = getApp();
    var ApiUrl = app.globalData.ApiUrl;  
    var special_id = options.special_id ?options.special_id:25;
     wx.request({
      url: ApiUrl + "/index.php?act=index&op=special&special_id=" + special_id,
      data: {"special_id": special_id},
      header: {
        'content-type': 'application/json' // 默认值
      },
      method:'get',
      dataType:'json',
      success:function(res){       
        var list = res.data.datas.list;  
        for (var i = 0; i < list.length; i++) {
          
          if (list[i]['adv_list']) {
            for (var j = 0; j < list[i]['adv_list']['item'].length; j++) {
             
              list[i]['adv_list']['item'][j]['url'] = that.buildUrl(list[i]['adv_list']['item'][j]['type'], list[i]['adv_list']['item'][j]['data']);
            }
          }
          if (list[i]['home1']) {
            list[i]['home1']['url'] = that.buildUrl(list[i]['home1']['type'], list[i]['home1']['data']);
          }
          if (list[i]['home2']) {
            list[i]['home2']['rectangle1url'] = that.buildUrl(list[i]['home2']['rectangle1_type'], list[i]['home2']['rectangle1_data']);
            list[i]['home2']['rectangle2'] = that.buildUrl(list[i]['home2']['rectangle2_type'], list[i]['home2']['rectangle2_data']);
            list[i]['home2']['square_url'] = that.buildUrl(list[i]['home2']['square_type'], list[i]['home2']['square_data']);
          }
          if (list[i]['home3']) {
            for (var q = 0; q < list[i]['home3']['item']['length']; q++) {
              list[i]['home3']['item'][q]['url'] = that.buildUrl(list[i]['home3']['item'][q]['type'], list[i]['home3']['item'][q]['data']);
            }
          }
          if (list[i]['home4']) {
            list[i]['home4']['rectangle1_url'] = that.buildUrl(list[i]['home4']['rectangle1_type'], list[i]['home4']['rectangle1_data']);
            list[i]['home4']['rectangle2_url'] = that.buildUrl(list[i]['home4']['rectangle2_type'], list[i]['home4']['rectangle2_data']);
            list[i]['home4']['square_url'] = that.buildUrl(list[i]['home4']['square_type'], list[i]['home4']['square_data']);
          }

        }  
        wx.setNavigationBarTitle({
          title: res.data.datas.special_desc
        })
        
        that.setData({
          list:list
        });

      }
      
    });
    
    
  },
  imageLoad:function(val){
    var type = val.target.dataset.type;
      var imgH = val.detail.height;
      var imgW = val.detail.width;
      var screeW = wx.getSystemInfoSync().windowWidth;
      var screeR = screeW / imgW;
      var height= imgH* screeR+"px";
      var that = this;
     switch(type){
       case "home1pic":
        that.setData({
          home1H: height
        });
        break;
      case　"advPic":
        that.setData({
          advPicH: height
        });break;
      case 　"goodsImg":
        that.setData({
          goodsH: screeW/2
        }); break;
 
    }
     
  },
  /*创建url*/
  buildUrl: function (type, data) {
    var WapSiteUrl = "";
    switch (type) {
      case 'keyword':
        return WapSiteUrl = '/pages/product_list/product_list?keyword=' + data;
      case 'special':
        return WapSiteUrl = '/pages/special/special?special_id=' + data;
      case 'goods':
        return WapSiteUrl = '/pages/product_detail/product_detail?goods_id=' + data;
      case 'url':
        return data;
    }
    return WapSiteUrl;

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})